package financeapi;
import java.util.*;
import java.io.*;

public class AuthorizerCollection {

	private Vector collection;

	public AuthorizerCollection()
	{
		collection = new Vector();

		// Read All Authorizors from a directory
		File f = new File(".\\plugin");
		String files[] = f.list();
		for(int i=0;i<files.length;i++)
		{
			String name = files[i].substring(0,files[i].indexOf('.'));
			try
			{
				DataAuthorizor authorize = (DataAuthorizor)Class.forName("plugin."+name).newInstance();
				System.out.println("Loaded "+authorize.getName()+" plugin");
				collection.addElement(authorize);
			}
			catch(Exception e)
			{

			}
		}
	}

	public Vector getAuthorizers()
	{
		Vector strings = new Vector();
		for(int i=0;i<collection.size();i++)
		{
			DataAuthorizor da = (DataAuthorizor)collection.elementAt(i);
			strings.addElement(da.getName());
		}

		return strings;
	}

	public DataAuthorizor getAuthorizerClass(String name)
	{
		DataAuthorizor retval=null;
		boolean notdone=true;
		for(int i=0;(i<collection.size()) && notdone;i++)
		{
			DataAuthorizor da = (DataAuthorizor)collection.elementAt(i);
			if(da.getName().equals(name))
			{
				notdone=true;
				retval = da;
			}
		}

		return retval;
	}
}
